package com.ocr.fragment;

import java.util.ArrayList;
import java.util.List;

import com.ocr.MainActivity;
import com.ocr.R;
import com.ocr.adapter.LanguageAdapter;
import com.ocr.entities.LanguageContext;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ListView;
import android.widget.Switch;

public class FragmentSetting extends Fragment {
	private ListView listViewLanguage;
	private LanguageAdapter languageAdapter;
	private Switch switchImgProcess;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View root = inflater.inflate(R.layout.fragment_setting, container,
				false);
		listViewLanguage = (ListView) root.findViewById(R.id.list_language);
		switchImgProcess = (Switch) root.findViewById(R.id.switch_image_processing);
		// create adapter
		languageAdapter = new LanguageAdapter(getActivity(),
				R.layout.item_language, LanguageContext.getListLanguages());
		listViewLanguage.setAdapter(languageAdapter);
		listViewLanguage.setItemsCanFocus(false);
		listViewLanguage.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
		//switch
		switchImgProcess.setChecked(MainActivity.SETTINGITEM.isAutoProcessImg());
		switchImgProcess.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				// TODO Auto-generated method stub
				MainActivity.SETTINGITEM.setAutoProcessImg(isChecked);
				MainActivity.SETTINGDAO.saveSetting(MainActivity.SETTINGITEM);
			}
		});
		return root;
	}
}
